package com.cby.operation.common.ext

import android.app.Fragment
import android.content.Context
import android.view.View

/**
 * @description: ResourceExt
 *
 * @author ChenBaoYang
 * @date 6/4/21 16:58
 */

private const val RES_ID = "id"
private const val RES_STRING = "string"
private const val RES_DRAWABLE = "drawable"
private const val RES_LAYOUT = "layout"
private const val RES_STYLE = "style"
private const val RES_COLOR = "color"
private const val RES_DIMEN = "dimen"
private const val RES_ANIM = "anim"
private const val RES_MENU = "menu"

fun Fragment.getId(resName: String?): Int {
    return activity!!.getId(resName)
}

fun Fragment.getStringId(resName: String?): Int {
    return activity!!.getStringId(resName)
}

fun Fragment.getDrawableId(resName: String?): Int {
    return activity!!.getDrawableId(resName)
}

fun Fragment.getLayoutId(resName: String?): Int {
    return activity!!.getLayoutId(resName)
}

fun Fragment.getStyleId(resName: String?): Int {
    return activity!!.getStyleId(resName)
}

fun Fragment.getColorId(resName: String?): Int {
    return activity!!.getColorId(resName)
}

fun Fragment.getDimenId(resName: String?): Int {
    return activity!!.getDimenId(resName)
}

fun Fragment.getAnimId(resName: String?): Int {
    return activity!!.getAnimId(resName)
}

fun Fragment.getMenuId(resName: String?): Int {
    return activity!!.getMenuId(resName)
}


/************************** 以下是View的资源扩展函数 ****************************/

fun View.getId(resName: String?): Int {
    return context.getId(resName)
}

fun View.getStringId(resName: String?): Int {
    return context.getStringId(resName)
}

fun View.getDrawableId(resName: String?): Int {
    return context.getDrawableId(resName)
}

fun View.getLayoutId(resName: String?): Int {
    return context.getLayoutId(resName)
}

fun View.getStyleId(resName: String?): Int {
    return context.getStyleId(resName)
}

fun View.getColorId(resName: String?): Int {
    return context.getColorId(resName)
}

fun View.getDimenId(resName: String?): Int {
    return context.getDimenId(resName)
}

fun View.getAnimId(resName: String?): Int {
    return context.getAnimId(resName)
}

fun View.getMenuId(resName: String?): Int {
    return context.getMenuId(resName)
}


/************************** 以下是Context的资源扩展函数 ****************************/
fun Context.getId(resName: String?): Int {
    return getResId(resName, RES_ID)
}

fun Context.getLayoutId(resName: String?): Int {
    return getResId(resName, RES_LAYOUT)
}

fun Context.getStringId(resName: String?): Int {
    return getResId(resName, RES_STRING)
}

fun Context.getDrawableId(resName: String?): Int {
    return getResId(resName, RES_DRAWABLE)
}

fun Context.getStyleId(resName: String?): Int {
    return getResId(resName, RES_STYLE)
}

fun Context.getColorId(resName: String?): Int {
    return getResId(resName, RES_COLOR)
}

fun Context.getDimenId(resName: String?): Int {
    return getResId(resName, RES_DIMEN)
}

fun Context.getAnimId(resName: String?): Int {
    return getResId(resName, RES_ANIM)
}

fun Context.getMenuId(resName: String?): Int {
    return getResId(resName, RES_MENU)
}

fun Context.getResId(
    resName: String?,
    defType: String?
): Int {
    return resources.getIdentifier(resName, defType, packageName)
}


